"""
@name : 文件作业
@author : yinbangyou
@projectname: 三创购物系统.py
"""

#小练习
# ip存储与读取文件统计ip频率前十
# import random
# with open("ips.txt","w+") as fp:
#     ip = '172.25.254.'
#     for i in range(100):
#         ip = '172.25.254.'
#         ip += (str(random.randrange(0,256,1)))
#         ip += '\n'
#         fp.write(ip)
# with open("ips.txt","r") as fp:
#     use_most = {}
#     str1=[]
#     for i in range(100):
#         str1 = fp.readline()[0:-1]
#         if str1 in use_most:
#             use_most[str1] = use_most.get(str1) + 1
#         else:
#             use_most[str1] = 1
# for i in range(10):
#     max_str = max(use_most, key=use_most.get)
#     # print(max(use_most, key=lambda k: use_most[k]))
#     print(max_str,use_most.get(max_str))
#     use_most.pop(max_str)

# 词频统计
# • 已经有一个瓦尔登湖的文本，
# “Walden.txt”
# • 统计这篇文章的词频（每个词出现的次数）
# • 不统计标点符号
# • The和the被统计成同一个词（不区分大小写）
# • 输出格式：{ 'the': 10,
# 'is': 45....}

# import re
# with open("Walden.txt","r",encoding="utf-8-sig") as fp:
#     str1 = fp.read()        #先把内容读进str1
#     pattern = re.compile(u'\t|\.|\+|&|!|$|-|:|;|\)|\(|\?|"|,|/|1|2|3|4|5|6|7|8|9|0|')  #定义正则表达式匹配模式
#     str1= re.sub(pattern,'',str1)#将符合模式的字符去除
#     # str1 = str1.replace('\n',' ')
#     str1=str1.split()
#     # print(str1,type(str1))
#     word_frequency = {}
#     for str2 in str1:
#         if str2.lower() in word_frequency:
#             word_frequency[str2.lower()] = word_frequency.get(str2.lower()) + 1
#         else:
#             word_frequency[str2.lower()] = 1
#     print(word_frequency)